<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            list-style: none;
            font-size: 20px;
        }
        .slider{
            margin: 0 auto;
            width: 700px;
            cursor: pointer;
        }
        .slider-wrapper {
            width: 700px;
            height: 800px;
        }

        .slider-wrapper img {
            width: 100%;
            height: 100%;
        }

        .slider-footer p {
            width: 700px;
        }

        .slider-footer {
            width: 700px;
            background-color: pink;
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
        }

        .slider-footer .list {
            margin-right: 110px;
            width: 400px;
            display: flex;
            flex-direction: row;
        }

        .slider-footer li {
            height: 30px;
            width: 30px;
            margin-right: 40px;
            opacity: 0.4;
            border-radius: 50%;
            background-color: white;
        }

        .slider-footer li.active {
            opacity: 1;
            background-color: black;
        }

        .slider-footer button {
            background-color: #fad1d1;
            font-size: 100px;
            color: rgb(101, 105, 108);
            border: none;
            cursor: pointer;
        }
        .slider-footer button:active{
            background-color: #f89898;
        }
    </style>
</head>

<body>
    <div class="slider">
        <div class="slider-wrapper">
            <a href="#">
                <img src="./线稿/image.png" alt="">
            </a>
            <!-- <img src="./线稿/image1.png" alt="">
            <img src="./线稿/image2.png" alt=""> -->
        </div>
        <div class="slider-footer">
            <p>今晚学会这几张</p>
            <ul class="list">
                <li class="active"></li>
                <li></li>
                <li></li>
            </ul>
            <button class="prev">&lt;</button>
            <button class="next">&gt;</button>
        </div>
    </div>
    <script>
        const sliderData = [
            { url: './线稿/image.png', title: '今晚学会这1张' },
            { url: './线稿/image1.png', title: '今晚学会这2张' },
            { url: './线稿/image2.png', title: '今晚学会这3张' },
        ]
        const img = document.querySelector('.slider-wrapper img')
        const p = document.querySelector('.slider-footer p')
        
        let i = 0
        const next = document.querySelector('.next')
        next.addEventListener('click',function(){
            i++
            i = i >= sliderData.length ? 0:i
            common()
        })

        const prev = document.querySelector('.prev')
        prev.addEventListener('click',function(){
            i--
            i = i <= -1 ? sliderData.length-1:i
            common()
        })

        function common(){
            img.src = sliderData[i].url
            p.innerHTML = sliderData[i].title
            document.querySelector('.slider-footer li.active').classList.remove('active')
            document.querySelector(`.slider-footer li:nth-child(${i + 1})`).classList.add('active')
        }

        let timeID = setInterval(function(){
            next.click()
        },1000)

        const slider = document.querySelector('.slider')
        slider.addEventListener('mouseenter',function(){
            clearInterval(timeID)
        })
        slider.addEventListener('mouseleave',function(){
            clearInterval(timeID)
            //先关后开
            timeID = setInterval(function(){
            next.click()
        },1000)
        })

    </script>
</body>

</html>